//
//  KeyboardViewController.m
//  Lesson
//
//  Created by centling on 15/4/23.
//  Copyright (c) 2015年 Seas.CHENG. All rights reserved.
//

#import "KeyboardViewController.h"

@interface KeyboardViewController ()

@end

@implementation KeyboardViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [[NSNotificationCenter defaultCenter] addObserver:self  selector:@selector(updateTextViewPositionForKeyboard:) name:UIKeyboardWillChangeFrameNotification object:nil];
}


-(void)dealloc{
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}


-(void)updateTextViewPositionForKeyboard:(NSNotification *)notification{
    NSTimeInterval duration=[notification.userInfo[UIKeyboardAnimationDurationUserInfoKey] doubleValue];
    UIViewAnimationCurve curve=[notification.userInfo[UIKeyboardAnimationCurveUserInfoKey] integerValue];
    CGRect keyboardEndFrame=[notification.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue];
//    keyboardEndFrame=[self.view convertRect:keyboardEndFrame fromView:nil];
    
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationCurve:curve];
    [UIView setAnimationDuration:duration];
    NSLog(@"%F  %f",self.textViewBottomSpaceToContainer.constant,CGRectGetMaxY(self.view.bounds)-keyboardEndFrame.origin.y);
    self.textViewBottomSpaceToContainer.constant=-(CGRectGetMaxY(self.view.bounds)-keyboardEndFrame.origin.y);
    [self.view layoutIfNeeded];
    [UIView commitAnimations];

}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

- (IBAction)closeKeyboard:(id)sender {
    [self.view endEditing:YES];
}
@end
